home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS12.ADF / Star10 / star10.asm < prev    next >
Assembly Source File  |  1986-08-05  |  17KB  |  629 lines

  1. *
  2. *  File: stars.asm                                   August 11, 1986
  3. *
  4. *  Version: 1.0
  5. *
  6. *  By: Andrew Tuline          CIS: 70465,1223
  7. *      Vancouver, B.C.
  8. *
  9. *  This program does the following:
  10. *
  11. *               opens intuition library
  12. *               opens a screen
  13. *               opens a window in workbench screen
  14. * top:
  15. *               draws starfield on screen
  16. *               checks for close window message
  17. *               if not pressed goto top
  18. *               closes a window in workbench screen
  19. *               closes a screen
  20. *               closes intuition library
  21. *               exits to CLI
  22. *
  23. * Assemble and link instructions as follows:
  24. *
  25. * 1) Put stars.asm and stin.asm into the root directory of your assembly
  26. *    language disk which is in drive df1: and execute the following:
  27. *
  28. *    cd df1:include
  29. *    :c/assem :stin.asm -o ram:stin.o -c w120000
  30. *    :c/assem :stars.asm -o ram:stars.o
  31. *    copy :lib/amiga.lib ram:
  32. *    cd ram:
  33. *    df1:c/alink from stars.o+stin.o to stars library amiga.lib
  34. *
  35. *
  36. * The reason for putting includes in a separate file and then included at
  37. * link time is to decrease assembly time for the main program during
  38. * development.
  39. *
  40. *     old colours       new colours
  41. *     ===========       ===========
  42. *     0 = blue          0 = black (background)
  43. *     1 = white         1 = white
  44. *     2 = black         2 = blue
  45. *     3 = yellow        3 = yellow
  46. *     4-7 = unused      4-7 = unused
  47. *
  48. * Note:  I originally wrote this program for the IBM PC.
  49. *        The Amiga version in comparison is not that fast.
  50. *        Other features to follow are:
  51. *
  52. *           speed variations
  53. *           turning
  54. *           doppler effect
  55. *           brightness vs. distance
  56. *
  57. * Two interesting notes not required by this program for programmers:
  58. *
  59. *        FUNC_CNT should be -30 in include/exec/funcdef.i  (DOS 1.1)
  60. *        CLI parameters are passed as: A0 has pointer, D0 has length
  61. *
  62. ***************************************************************************
  63.  
  64.  
  65. * Macros
  66.  
  67. EXT_SYS  MACRO
  68.          XREF     _LVO\1
  69.          ENDM
  70.  
  71. SYS      MACRO
  72.          JSR      _LVO\1
  73.          ENDM
  74.  
  75.  
  76. * System calls (some aren't currently used) (they are defined in amiga.lib)
  77.  
  78. * exec calls
  79.          EXT_SYS  OpenLibrary             * (libName,version)(A1,D0)
  80.          EXT_SYS  CloseLibrary            * (libbNode)(A1)
  81.          EXT_SYS  GetMsg                  * (msgPort)(D0)
  82.          EXT_SYS  ReplyMsg                * (message)(A1)
  83.          EXT_SYS  Wait                    * (signalSet)(D0)
  84.  
  85. * intuition calls
  86.          EXT_SYS  OpenWindow              * (newWindow)(A0)
  87.          EXT_SYS  CloseWindow             * (Window)(A0)
  88.          EXT_SYS  OpenScreen              * (newScreen)(A0)
  89.          EXT_SYS  CloseScreen             * (Screen)(A0)
  90.          EXT_SYS  ShowTitle               * (Screen,ShowIt)(A0,D0)
  91.  
  92. * graphics calls
  93.          EXT_SYS  Draw                    * (rp,x,y)(A1,D0,D1)
  94.          EXT_SYS  Move                    * (rp,x,y)(A1,D0,D1)
  95.          EXT_SYS  ReadPixel               * (rp,x,y)(A1,D0,D1)
  96.          EXT_SYS  SetAPen                 * (rp,pennum)(A1,D0:8)
  97.          EXT_SYS  SetDrMd                 * (rp,drawmode)(A1,D0)
  98.          EXT_SYS  SetRGB4                 * (vp,n,r,g,b)(a0,d0,d1:4,d2:4,d3:4)
  99.          EXT_SYS  WritePixel              * (rp,x,y)(A1,D0,D1)
  100.          EXT_SYS  SetRast                 * (rp,pennum)(A1,D0)
  101.  
  102. * externally defined variables
  103.          XREF     _AbsExecBase            * see amiga.lib
  104.  
  105.          XREF     ns_DefaultTitle         * see include files
  106.          XREF     sc_RastPort
  107.          XREF     sc_ViewPort
  108.          XREF     nw_Title
  109.          XREF     RP_JAM1
  110.          XREF     wd_UserPort
  111.          XREF     im_Class                * IDCMP class long word
  112.          XREF     MP_SIGBIT
  113.          XREF     CLOSEWINDOW
  114.          XREF     CUSTOMSCREEN            * not currently used
  115.          XREF     WBENCHSCREEN
  116.  
  117.          XREF     ANDREWSGADGETS          * see stin.asm
  118.          XREF     IDCMP_FLAGS
  119.  
  120. **************************************************************************
  121. *  Start of Code                                                         *
  122. **************************************************************************
  123.  
  124. startup:
  125.          move.l   sp,savesp
  126.  
  127.          jsr      openlibraries
  128.          jsr      openmystuff
  129.          jsr      setcolours
  130.          jsr      starinstall
  131. redostars:
  132.          jsr      starun
  133.          jsr      getmsg                  * d0 has pointer to message
  134.          tst.l    d0
  135.          beq      redostars               * jump back if no message pointer
  136.  
  137.          move.l   d0,a0
  138.          move.l   im_Class(a0),d0
  139.          andi.l   #CLOSEWINDOW,d0
  140.          beq      redostars               * jump back if not CLOSEWINDOW msg
  141.  
  142. *         jsr      replymsg                * should be right after getmsg
  143.  
  144. stopprog:
  145.          jsr      closeall
  146.  
  147. exitprog:
  148.          move.l   savesp,sp
  149.          rts
  150.  
  151. *****************************************************
  152.  
  153. *  Open Intuition Library
  154.  
  155. openlibraries:
  156.          move.l   _AbsExecBase,a6
  157.          lea.l    theintuition,a1
  158.          moveq    #0,d0
  159.          SYS      OpenLibrary(a6)
  160.          move.l   d0,intuitionbase        * d0 is passed back
  161.          beq      openerr
  162.  
  163.  
  164. * Open Graphics Library
  165.  
  166.          move.l   _AbsExecBase,a6
  167.          lea.l    thegraphics,a1
  168.          moveq    #0,d0
  169.          SYS      OpenLibrary(a6)
  170.          move.l   d0,graphicsbase
  171.          beq      openerr
  172.  
  173.          rts
  174.  
  175. **************************************************************
  176.  
  177. * Open a screen
  178.  
  179. openmystuff:
  180.          move.l   intuitionbase,a6
  181.          lea      screenvars,a0
  182.          SYS      OpenScreen(a6)
  183.          move.l   d0,newscreenptr         * d0 has address of screen
  184.          beq      openerr
  185.  
  186.          add.l    #sc_RastPort,d0         * get the rastport value
  187.          move.l   d0,myraster
  188.          sub.l    #sc_RastPort,d0
  189.          add.l    #sc_ViewPort,d0         * get the viewport value
  190.          move.l   d0,myview
  191.  
  192.          move.l   intuitionbase,a6        * hide the screentitle
  193.          move.l   newscreenptr,a0
  194.          move.l   #0,d0
  195.          SYS      ShowTitle(a6)
  196.  
  197. * Open a window
  198.  
  199.          move.l   intuitionbase,a6
  200.          lea      windowvars,a0
  201.          SYS      OpenWindow(a6)
  202.          move.l   d0,newwindowptr
  203.          beq      openerr
  204.  
  205.          rts
  206.  
  207. *************************************************************
  208.  
  209.  
  210. setcolours:
  211.  
  212. * Set the background to black and the other to blue (flip 0 and 2)
  213.  
  214. setblackback:
  215.          move.l   graphicsbase,a6
  216.          move.l   myview,a0
  217.          move.l   #0,d0                   * set colour 0 to:
  218.          move.b   #0,d1                   * red   +
  219.          move.b   #0,d2                   * green +----> black
  220.          move.b   #0,d3                   * blue  +
  221.          SYS      SetRGB4(a6)
  222.  
  223.          move.l   graphicsbase,a6
  224.          move.l   myview,a0
  225.          move.l   #2,d0                   * set colour 2 to:
  226.          move.b   #0,d1                   * red   +
  227.          move.b   #0,d2                   * green +----> blue
  228.          move.b   #10,d3                  * blue  +
  229.          SYS      SetRGB4(a6)
  230.  
  231.  
  232.  
  233. * Set the drawing mode
  234.  
  235.          move.l   graphicsbase,a6
  236.          move.l   myraster,a1
  237.          move.b   RP_JAM1,d0
  238.          SYS      SetDrMd(a6)
  239.  
  240.          rts
  241.  
  242.  
  243. *************************************************************
  244.  
  245. starinstall:
  246.  
  247.          lea      pont,a3
  248.          lea      pontend,a4
  249. newstars:
  250.          jsr      point_maker
  251.          add.w    #lenth,a3
  252.          cmpa.l   a4,a3
  253.          blt      newstars
  254.  
  255.          move.b   #1,speed                * initialize various parmeters
  256.          move.w   #160*64,x_centre
  257.          move.w   #99*64,y_centre
  258.          move.w   #0,x_abs
  259.          move.w   #0,y_abs
  260.  
  261.          rts
  262.  
  263. *************************************************************
  264.  
  265. starun:
  266.          lea      pont,a3
  267.          lea      pontend,a4
  268. starup:
  269.          move.b   speed,d4
  270.          move.w   xold_st(a3),d2
  271.          move.w   d2,d5
  272.          sub.w    x_centre,d5
  273.          asr.w    d4,d5                   * shift delx by speed factor
  274.  
  275.          move.b   dx_st(a3),d4
  276.          asr.w    d4,d5                   * distance across factor
  277.  
  278.          add.w    d5,d2
  279.          sub.w    x_abs,d2
  280.          sub.w    x_abs,d2
  281.  
  282.          cmp.w    #x_rang,d2
  283.          bcc      str_out_rang
  284.          cmp.w    #xlower,d2
  285.          bls      str_out_rang
  286.  
  287.          move.w   d2,xnew_st(a3)
  288.  
  289.          move.b   speed,d4
  290.  
  291.          move.w   yold_st(a3),d2          * d2 <- yold
  292.          move.w   d2,d5
  293.          sub.w    y_centre,d5
  294.          asr.w    d4,d5
  295.  
  296.          move.b   dx_st(a3),d4
  297.          asr.w    d4,d5
  298.  
  299.          add.w    d5,d2
  300.          sub.w    y_abs,d2
  301.          sub.w    y_abs,d2
  302.  
  303.          cmp.w    #y_rang,d2
  304.          bcc      str_out_rang
  305.          cmp.w    #ylower,d2
  306.          bls      str_out_rang
  307.  
  308.          move.w   d2,ynew_st(a3)
  309.  
  310.          move.w   xold_st(a3),d0          * preset old point
  311.          move.w   yold_st(a3),d1
  312.          bsr      preset
  313.  
  314.          move.w   xnew_st(a3),d0          * pset new point
  315.          move.w   ynew_st(a3),d1
  316.          bsr      pset
  317.  
  318.          move.w   xnew_st(a3),xold_st(a3)
  319.          move.w   ynew_st(a3),yold_st(a3)
  320.  
  321.          bra      next_star
  322.  
  323. str_out_rang:
  324.  
  325.          move.w   xold_st(a3),d0
  326.          move.w   yold_st(a3),d1
  327.          bsr      preset
  328.          bsr      point_maker
  329.  
  330. next_star:
  331.          add.w    #lenth,a3
  332.          cmpa.l    a4,a3
  333.          blt      starup
  334.  
  335. starend:
  336.          rts
  337.  
  338. *************************************************************
  339.  
  340. preset:
  341.  
  342.          move.l   d0,d3
  343.          move.l   d1,d4
  344.          move.b   #0,d0                   * 0 = black
  345.          move.l   myraster,a1
  346.          move.l   graphicsbase,a6
  347.          SYS      SetAPen(a6)
  348.          move.l   d3,d0
  349.          move.l   d4,d1
  350.  
  351.          lsr.w    #6,d0
  352.          lsr.w    #6,d1
  353.          and.l    #$ffff,d0
  354.          and.l    #$ffff,d1
  355.  
  356.          SYS      WritePixel(a6)
  357.  
  358.          rts
  359.  
  360. *************************************************************
  361.  
  362. pset:
  363.  
  364.          move.l   d0,d3
  365.          move.l   d1,d4
  366.          move.b   #1,d0                   * 1 = white
  367.          move.l   graphicsbase,a6
  368.          move.l   myraster,a1
  369.          SYS      SetAPen(a6)
  370.          move.l   d3,d0
  371.          move.l   d4,d1
  372.  
  373.          lsr.l    #6,d0
  374.          lsr.l    #6,d1
  375.          and.l    #$ffff,d0
  376.          and.l    #$ffff,d1
  377.  
  378.          SYS      WritePixel(a6)
  379.  
  380.          rts
  381.  
  382. *************************************************************
  383.  
  384. point_maker:
  385.          jsr      rando                   * x values
  386.          move.w   d0,d2
  387.          and.w    #x_and,d0
  388.          add.w    #xlower,d0
  389.          move.w   d0,xold_st(a3)
  390.  
  391.          jsr      rando                   * y values
  392.          and.w    #y_and,d0
  393.          add.w    #ylower,d0
  394.          cmp.w    #y_rang,d0
  395.          bls      rep_y
  396.          asr.w    #1,d0
  397. rep_y:
  398.          move.w   d0,yold_st(a3)
  399.  
  400.          and.b    #3,d2                   * side distance factor
  401.          add.b    #1,d2
  402.          move.b   d2,dx_st(a3)
  403.          rts
  404.  
  405.  
  406. **********************************************************
  407.  
  408. * Random number generator with d0 returning the number (others saved)
  409.  
  410. randomize:
  411.          move.w   #91,d0                  * the seed
  412.          move.w   d0,rndsav
  413.          move.b   #91,d0
  414.          move.b   d0,rndlow
  415.          rts
  416.  
  417. rando:
  418.          move.l   a0,-(sp)
  419.          move.l   d1,-(sp)
  420.  
  421.          lea      rndsav,a0
  422.          move.w   #$4321,d0
  423.          mulu     (a0),d0
  424.          add.l    #1,d0
  425.          move.w   d0,(a0)
  426.          move.b   (a0),d1
  427.          eor.b    d0,d1
  428.          move.b   d1,rndlow
  429.  
  430.          move.l   (sp)+,d1
  431.          move.l   (sp)+,a0
  432.          rts
  433.  
  434. ************************************************************
  435. * get message to see if user closed the window
  436.  
  437. getmsg:
  438.          move.l   _AbsExecBase,a6
  439.          move.l   newwindowptr,a0
  440.          move.l   wd_UserPort(a0),a0
  441.          SYS      GetMsg(a6)
  442.          rts
  443.  
  444. ************************************************************
  445. * reply to the current message
  446.  
  447. replymsg:
  448.          move.l   d0,a1
  449.          move.l   _AbsExecBase,a6
  450.          SYS      ReplyMsg(a6)
  451.          rts
  452.  
  453. ************************************************************
  454. * Wait for user to close the window
  455.  
  456. waitforbutton:
  457.          move.l   _AbsExecBase,a6
  458.          move.l   newwindowptr,a0
  459.          move.l   wd_UserPort(a0),a1
  460.          move.l   #0,d3
  461.          move.b   MP_SIGBIT(a1),d3
  462.          move.l   #1,d0
  463.          asl.l    d3,d0
  464.          SYS      Wait(a6)
  465.  
  466.          rts
  467.  
  468. *************************************************************
  469.  
  470. * Close a window
  471.  
  472. closeall:
  473.          move.l   intuitionbase,a6
  474.          move.l   newwindowptr,a0
  475.          SYS      CloseWindow(a6)
  476.  
  477.  
  478. * Close a screen
  479.  
  480.          move.l   intuitionbase,a6
  481.          move.l   newscreenptr,a0
  482.          SYS      CloseScreen(a6)
  483.  
  484.  
  485. * Close the graphics library
  486.  
  487.          move.l      graphicsbase,a1
  488.          move.l      _AbsExecBase,a6
  489.          SYS         CloseLibrary(a6)
  490.  
  491.  
  492. *  Close the intuition library
  493.  
  494.          move.l   intuitionbase,a1
  495.          move.l   _AbsExecBase,a6
  496.          SYS      CloseLibrary(a6)
  497.  
  498.          rts
  499.  
  500. *************************************************************
  501.  
  502. openerr:
  503.          moveq    #-1,d1                  * return code=bad
  504.          move.l   d1,d0
  505.          bra      exitprog
  506.  
  507.  
  508. ****************************************************************************
  509.  
  510. *  Library definitions
  511.  
  512. theintuition   dc.b    'intuition.library',0
  513.                cnop  0,2
  514.  
  515. thegraphics    dc.b     'graphics.library',0
  516.                cnop  0,2
  517.  
  518.  
  519. *  Andrew's Title definitions
  520.  
  521. andrews_window dc.b   '3D Stars V 1.0',0
  522.                cnop  0,2
  523.  
  524. andrews_screen dc.b  'Andrew',39,'s Screen',0
  525.                cnop  0,2
  526.  
  527.  
  528. * Uninitialized variable definitions
  529.  
  530. Uninitdata     section  vars,bss
  531.  
  532. startbss
  533.  
  534. intuitionbase  ds.l  1                    * base addr. for intuit. calls
  535. graphicsbase   ds.l  1                    * base addr. for graphics calls
  536.  
  537. myraster       ds.l  1                    * pointer to new screen raster
  538. myview         ds.l  1                    * pointer to new screen viewport
  539.  
  540. newwindowptr   ds.l  1                    * pointer to new window
  541. newscreenptr   ds.l  1                    * pointer to new screen
  542.  
  543. rndsav         ds.w  2
  544. rndlow         ds.b  4
  545.  
  546. savesp         ds.l  1
  547.  
  548. * star variables
  549.  
  550. speed          ds.b  2
  551.  
  552. numb           equ   $40
  553. lenth          equ   $10
  554.  
  555. pont           ds.b  numb*lenth
  556. pontend        ds.b  1
  557.  
  558. x_centre       ds.w  1
  559. y_centre       ds.w  1
  560. x_abs          ds.w  1
  561. y_abs          ds.w  1
  562.  
  563. xnew_st        equ   0
  564. ynew_st        equ   2
  565. dx_st          equ   4
  566. dy_st          equ   6
  567. xold_st        equ   8
  568. yold_st        equ   $a
  569. viaddr         equ   $c
  570. vidata         equ   $e
  571.  
  572. x_and          equ   254*$40
  573. x_rang         equ   318*64
  574. zero           equ   0
  575. y_and          equ   254*$40
  576. y_rang         equ   197*64
  577.  
  578. xlower         equ   3*$40
  579. ylower         equ   11*$40
  580. endbss
  581.  
  582.  
  583. * Initialized variable defintions
  584.  
  585. initdata       section  vars,data
  586.  
  587. startdata
  588.  
  589. windowvars     dc.w  0                    * nw_LeftEdge
  590.                dc.w  0                    * nw_TopEdge
  591.                dc.w  320                  * nw_Width
  592.                dc.w  200                  * nw_Height
  593.                dc.b  0                    * nw_DetailPen
  594.                dc.b  1                    * nw_BlockPen
  595.                dc.l  IDCMP_FLAGS          * nw_IDCMPFlags
  596.                dc.l  ANDREWSGADGETS       * nw_FLAGS
  597.                dc.l  0                    * nw_FirstGadget
  598.                dc.l  0                    * nw_CheckMark
  599.                dc.l  andrews_window       * nw_Title
  600.                dc.l  0                    * nw_Screen
  601.                dc.l  0                    * nw_BitMap
  602.                dc.w  0                    * nw_Minwidth
  603.                dc.w  0                    * nw_MinHeight
  604.                dc.w  320                  * nw_MaxWidth
  605.                dc.w  200                  * nw_MaxHeight
  606.                dc.w  WBENCHSCREEN         * nw_Type
  607.  
  608.  
  609.  
  610. screenvars     dc.w  0                    * ns_LeftEdge
  611.                dc.w  0                    * ns_TopEdge
  612.                dc.w  320                  * ns_Width
  613.                dc.w  200                  * ns_Height
  614.                dc.w  3                    * ns_Depth
  615.                dc.b  3                    * ns_DetailPen
  616.                dc.b  1                    * ns_BlockPen
  617.                dc.w  0                    * ns_ViewModes
  618.                dc.w  WBENCHSCREEN         * ns_Type
  619.                dc.l  0                    * ns_Font
  620.                dc.l  andrews_screen       * ns_DefaultTitle
  621.                dc.l  0                    * ns_Gadgets
  622.                dc.l  0                    * ns_CustomBitMap
  623.  
  624.  
  625. enddata
  626.  
  627.       end
  628.  
  629.